package de.tapps.brainstorming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.telephony.TelephonyManager;
import android.util.Log;

public class IsAdmin extends AsyncTask<String, Integer, String> {
private MainActivity activity = new MainActivity();
private Crypter crypter;
public IsAdmin(MainActivity act){

	activity = act;
	crypter = new Crypter(activity);


}
		
		@Override
		protected String doInBackground(String... arg0) {
			new Thread(new Runnable() {
				public void run() {
					URL url = null;
					TelephonyManager telephonyManager = (TelephonyManager) activity.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
					String imei = telephonyManager.getDeviceId();
					

					try {
						
						url = new URL(
								"http://t-apps-online.de/BrainStorming/isAdmin.php?"+crypter.splitGetParameter(crypter.encrypt(imei)));
						Log.e("Url","URl"+"http://t-apps-online.de/BrainStorming/isAdmin.php?"+crypter.splitGetParameter(crypter.encrypt(imei)));
						String readLine = null;
						BufferedReader buffReader = new BufferedReader(
								new InputStreamReader(url.openStream()));
						while ((readLine = buffReader.readLine()) != null) {
							
							
									if (readLine.equals("1")){
										
activity.isAdmin = true;
									}
							else{
							
activity.isAdmin = false;

							}
							
						}
						
					} catch (MalformedURLException me) {
						me.printStackTrace();
					} catch (IOException ioe) {
						ioe.printStackTrace();
					}
					catch (NullPointerException e){
					}
					
				}
			}).start();
			return null;
		}
}

